package com.bienvenue.main.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.afollestad.materialdialogs.MaterialDialog;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @ProjectName: Bienvenue
 * @Package: com.bienvenue.main.base
 * @ClassName: BaseFragment
 * @Description: java类作用描述
 * @Author: Mr.Chen
 * @CreateDate: 2020/9/7 11:02
 * @UpdateUser: Mr.Chen
 * @UpdateDate: 2020/9/7 11:02
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */


public abstract class BaseFragment extends Fragment {

    Unbinder unbinder;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutId(), null);
        unbinder = ButterKnife.bind(this, view);
        initView(view );
        initData();
        return view;
    }

    protected abstract void initData();

    protected abstract void initView(View view);

    protected abstract int getLayoutId();

    public void showToast(String content) {
        Toast.makeText(getContext(), content, Toast.LENGTH_SHORT).show();
    }

    public void showLog(String log) {
        Log.e("TAG", log);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }

    public MaterialDialog initDialog(String content) {
        MaterialDialog dialog = new MaterialDialog.Builder(getContext())
                .content(content)
                .progress(true, 100)
                .cancelable(false)
                .build();
        return dialog;
    }



    protected String getTime(Date date) {//可根据需要自行截取数据显示
        Log.d("getTime()", "choice date millis: " + date.getTime());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }
}
